********************************************************************************
*This file produces the following figures:
* Figure 5 (a)
* Figure 6 (a)
* Figure 7 (a)
* Figure 8 (a)
*NOTE: User may need to install the kdens2 package using "ssc install kdens2"
********************************************************************************


clear all
set more off


use Comb_data_6_sessions


kdens2 m_a m_b if is_observed == 1 & revenue_round == 1, n(100) nodraw saving(observed_revenue) replace
kdens2 m_a m_b if is_observed == 1 & revenue_round == 0, n(100) nodraw saving(observed_crash) replace
kdens2 m_a m_b if is_observed == 0 & revenue_round == 1, n(100) nodraw saving(unobserved_revenue) replace
kdens2 m_a m_b if is_observed == 0 & revenue_round == 0, n(100) nodraw saving(unobserved_crash) replace


clear
use observed_revenue
********************************************************************************
*Figure 5 (b)
twoway contour d _m_a _m_b if _m_a>= 0 & _m_b >=0 & _m_a<=0.9 & _m_b<=0.9, ///
crule(intensity) name(observed_revenue_heat, replace) levels(20) ///
zlabel(#7, format(%9.0f)) xscale(range(0 0.9)) yscale(range(0 0.9)) ///
title("Monitoring probabilities, observed, revenue max")
********************************************************************************

clear
use observed_crash
********************************************************************************
*Figure 6 (b)
twoway contour d _m_a _m_b if _m_a>= 0 & _m_b >=0 & _m_a<=0.9 & _m_b<=0.9, ///
crule(intensity) name(observed_crash_heat, replace) levels(20) ///
zlabel(#7, format(%9.0f)) xscale(range(0 0.9)) yscale(range(0 0.9)) ///
title("Monitoring probabilities, observed, crash min")
********************************************************************************


clear
use unobserved_revenue
********************************************************************************
*Figure 7 (b)
twoway contour d _m_a _m_b if _m_a>= 0 & _m_b >=0 & _m_a<=0.9 & _m_b<=0.9, ///
crule(intensity) name(unobserved_revenue_heat, replace) levels(20) ///
zlabel(#7, format(%9.0f)) xscale(range(0 0.9)) yscale(range(0 0.9)) ///
title("Monitoring probabilities, unobserved, revenue max")
********************************************************************************

clear
use unobserved_crash
********************************************************************************
*Figure 8 (b)
twoway contour d _m_a _m_b if _m_a>= 0 & _m_b >=0 & _m_a<=0.9 & _m_b<=0.9, ///
crule(intensity) name(unobserved_crash_heat, replace) levels(20) ///
zlabel(#7, format(%9.0f)) xscale(range(0 0.9)) yscale(range(0 0.9)) ///
title("Monitoring probabilities, unobserved, crash min")
********************************************************************************


